$(function () {

    $("#a").bootstrapTable({
        method:"post",
        contentType:'application/json',
        url:"/DFile/like",
        striped:true,
        pageNumber:1,
        pagination:true,
        sidePagination:'server',
        pageSize:3,
        pageList:[2,3,5,6],
        queryParams:function (parmes) {
            return{
                pageNum:(parmes.offset / parmes.limit) + 1,
                pageSize:parmes.limit,
                registerTime:$("#registerTime").val(),
                checked:$("#checked").val(),
            }
        },
        columns:[
            {title:"产品编号",field:"productId",align:'center'},
            {title:"产品名称",field:"productName",align:'center'},
            {title:"档次级别",field:"designProcedureTag",align:'center',
                formatter:function (value,row,index) {
                  if (value=1){
                      return "高档"
                  }if (value=2){
                      return "中档"
                    }
                    if (value=3){
                        return "低档"
                    }
                }
            },
            {title:"I级分类",field:"firstKindName",align:'center'},
            {title:"II级分类",field:"secondKindName",align:'center'},
            {title:"III级分类",field:"thirdKindName",align:'center'},
            {title:"产品经理",field:"responsiblePers",align:'center'},
            {title:"制定设计单",field:"productId",align:'center',
                formatter:function (value,row,index) {
                    var a="<a  href='cpscgxsj.html?id="+value+"?cpmc="+encodeURI(row.productName)+"'>制定设计单</a>";
                    return a;
                }
            },
        ]
    })
})


function scgxsjdSelect() {
    $("#a").bootstrapTable("refresh")}

function fanhuiym() {
    location.href="zdcpscgxsjd.html";
}


$("#a1").click(function () {
    let tab = document.getElementById("gxtab");
    tab.innerHTML+="<tr class='item'><td><input type='checkbox' class='gx' value='1'></td><td class='gxname'>组装</td><td class='gxbh'>01</td><td class='gxms'></td>" +
        "<td><input class='gsh' type='number'></td><td><input value='h' name='gsdw' readonly></td><td ><input type='number' class='dwgsscb'></td>" +
        "<td><label class='zcb'></label></td></tr>"
    $(this).unbind("click");
})

$("#a2").click(function () {
    let tab = document.getElementById("gxtab");
    tab.innerHTML+="<tr class='item'><td><input type='checkbox' class='gx' value='2'></td><td class='gxname'>测试</td><td class='gxbh'>02</td><td class='gxms'></td>" +
        "<td><input class='gsh' type='number'></td><td><input value='h' name='gsdw' readonly></td><td ><input class='dwgsscb' type='number'></td>" +
        "<td ><label class='zcb'></label></td></tr>"
    $(this).unbind("click");
})


$("#a3").click(function () {
    let tab = document.getElementById("gxtab");
    tab.innerHTML+="<tr class='item'><td><input type='checkbox' class='gx' value='3'></td><td class='gxname'>包装</td><td class='gxbh'>03</td><td class='gxms'></td>" +
        "<td><input class='gsh' type='number'></td><td><input value='h' name='gsdw' readonly></td><td ><input class='dwgsscb' type='number'></td>" +
        "<td><label class='zcb'></label></td></tr>"
    $(this).unbind("click");
})

function gxdel() {
        let xxx = $(".gx:checked");
        for (i=0;i<xxx.length;i++){
            $(xxx[i]).parents(".item").remove()
        }
}


function yulan() {
        let gsh=$(".gsh")
        let dgcb=$(".dwgsscb")
        let zcb=$(".zcb")
    //总工时成本
    let cb=0;
    for (i=0;i<gsh.length;i++){
        zcb[i].innerHTML=gsh[i].value*dgcb[i].value;
        cb=parseInt(cb)+parseInt(zcb[i].innerHTML);
    }
    $("[name=moduleCostPriceSum]").val(cb)

    $("#addgx").hide()
    $("#delgx").hide()
    $("#ylgx").hide()
    $("#qr1").show()
}


function querenaddgx() {
    var name=$("#name").html()
    var bh=$("#bh").html()
    var sjr=$("[name=designer]").val()
    var zongcb=$("[name=moduleCostPriceSum]").val()
    var djir=$("[name=register]").val()
    var sj=$("[name=registerTime]").html()
    var sjyq=$("#comment").val()

    var gxxh=$(".gx");
    var gxname=$('.gxname')
    var gxms=$('.gxms')
    var gsh=$('.gsh')
    var gsdw=$('[name=gsdw]')
    var dwgsscb=$('.dwgsscb')
    var zcb=$(".zcb")

    let arr=[];
    for (let i=0;i<gxxh.length;i++){
        let gxmx={id:null,parentId:null,detailsNumber:(i+1),procedureName:gxname[i].innerHTML,labourHourAmount:gsh[i].value,
            procedureDescribe:gxms[i].innerHTML,amountUnit:gsdw[i].value,costPrice:dwgsscb[i].value,subtotal:zcb[i].innerHTML,register:djir,
            registerTime:sj,designModuleTag:0,designModuleChangeTag:0}
        arr[i]=gxmx
    }

    let sjb={id:null,productId:bh,productName:name,costPriceSum:zongcb,designer:sjr,register:djir,registerTime:sj,procedureDescribe:sjyq,list:arr}

    if (confirm("确定提交吗？")){
        $.ajax({
            type:"post",
            contentType:"application/json;charset:utf-8",
            url:"/DFile/addgx",
            data:JSON.stringify(sjb),
            async:true,
            success:function (data) {
                location.href="/dengtao/zdcpscgxsjd.html"
            }

        })
    }

}


